package org.restoran.service;

import java.io.Writer;
import java.util.Collection;

/**
 * Generic parsing interface for entity parsing
 *
 * @code E - entity for parsing.
 */
public interface BeanParserService<E> {

    /**
     * Parse entity to custom json
     * @param entity entity object
     * @return  json as String
     */
    String parseToJson(E entity);

    /**
     * Write parsed json, by entity fields, string to {@link Writer}
     * @param writer {@link Writer}
     * @param entity parse entity
     * @return 
     */
    void parseToJson(Writer writer, E entity);

    /**
     * Parse collection to json
     * @param objects collection
     * @return json
     */
    String parseToJson(Collection<E> objects);

    void parseToJson(Writer writer, Collection<E> args);

    /**
     * Parse to entity json by using some custom format.
     * @param json json string
     * @param type type for entity
     * @return entity instance
     */
    E parseFromJson(String json, Class<E> type);
}
